package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.*;
	import flash.utils.getTimer;
	
	/** An animated display providing the context for the game */
	public class StoryPanel extends MovieClip
	{
		public var WIDTH:Number, HEIGHT:Number;
		
		// private objects
		private var tfield:TextField;
		private var squareParent:ParentPolygon, triangleParent:ParentPolygon;
		// private variables
		private var sceneTimestamp:int, sceneDuration:int;
		
		public function StoryPanel(WIDTH:Number, HEIGHT:Number)
		{
			this.WIDTH = WIDTH;
			this.HEIGHT = HEIGHT;
			this.addEventListener( Event.ADDED , handleAdded);
		}
		private function handleAdded(event:Event):void
		{
			this.removeEventListener(Event.ADDED, handleAdded);
			this.graphics.lineStyle(4, 0x006600);
			this.graphics.beginFill(0xDDFFDD,1);
			this.graphics.drawRect(0,0,WIDTH,HEIGHT);
			this.graphics.endFill();
			tfield = new TextField();
			tfield.mouseEnabled = false;
			tfield.selectable = false;
			tfield.defaultTextFormat = new TextFormat("arial", 20, 0x006600,null,null,null,null,null,"left");
			tfield.width = WIDTH - 20;
			tfield.wordWrap = true;
			tfield.x = 10;
			tfield.y = 10;
			this.addChild(tfield);
			// draw initial shapes
			squareParent = new ParentPolygon(WIDTH/4, HEIGHT/4, "square", "", ShapeProductionTask.TYPES); 
			squareParent.x = squareParent.WIDTH + 20;
			squareParent.y = this.height/2;
			this.addChild(squareParent);
			triangleParent = new ParentPolygon(WIDTH/4, HEIGHT/4, "equilateral_triangle", "", ShapeProductionTask.TYPES);
			triangleParent.x = WIDTH-triangleParent.WIDTH - 20;
			triangleParent.y = this.height/2;
			this.addChild(triangleParent);
			startScene1();	
			
		}
		
		/** Scene 1:  All types of shapes live in Polygonia, here's a triangle and a square
		 * Show triangle and square moving a bit
		 * */
		private function startScene1():void
		{
			tfield.text = "Welcome to Polygonia, where all types of shapes live together.";
			sceneDuration = 2000;
			sceneTimestamp = flash.utils.getTimer();
			this.addEventListener(Event.ENTER_FRAME, handleScene1);
		}
			private function handleScene1(event:Event):void
			{
				if (flash.utils.getTimer() - sceneTimestamp < sceneDuration)
				{
					
				} else 
				{
					completeScene1();
				}
			}
			private function completeScene1():void
			{
				this.removeEventListener(Event.ENTER_FRAME, handleScene1);
				this.dispatchEvent(new Event(Event.COMPLETE));
			}
		
		/** Scene 2:  In Polygonia, shapes grow out of the ground like flowers 
		 * Grow a child shape
		 * */
		
	}
}